{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d0f0517a",
   "metadata": {},
   "source": [
    "# 课程介绍\n",
    "> 本课程目标：数据挖掘+\n",
    "\n",
    "##  [joyfulpandas]\n",
    "-----\n",
    "> 1. [joyfulpandas](http://joyfulpandas.datawhale.club/)\n",
    "> 2. [学习目录](http://joyfulpandas.datawhale.club/Content/index.html)\n",
    "> 3. [线下资源链接](http://joyfulpandas.datawhale.club/pandas%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86%E4%B8%8E%E5%88%86%E6%9E%90.html)\n",
    "> 4. [线上资源阅读-电子书](https://gitee.com/xzhichao/data_analysis/blob/master/%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%BA%90/joyfulpandas.pdf)\n",
    "> 5. 代码资源\n",
    ">> 1. [代码资源1](http://joyfulpandas.datawhale.club/Content/index.html)\n",
    ">> 2. [代码资源2-含data-source](https://github.com/datawhalechina/joyful-pandas)\n",
    "\n",
    "## [JupyterLab]\n",
    "-----\n",
    "> 1.focused on interactive\n",
    "\n",
    "> 2.focused on exploratory computing\n",
    "\n",
    "## [Pandas]\n",
    "-----\n",
    "> 1. [pandas cheat sheet 查询表](https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf)\n",
    "> 2. [pandas Getting started](https://pandas.pydata.org/getting_started.html)\n",
    " >> 1. 环境搭建\n",
    " >> 2. [Tutorials](https://jupyterlab.readthedocs.io/en/stable/user/interface.html)\n",
    " >> 3. [Books](https://amzn.to/3DyLaJc)\n",
    " >> 4. [Videos资源](https://jupyterlab.readthedocs.io/en/stable/user/interface.html)\n",
    "## [Requests—html]\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce69be03",
   "metadata": {},
   "source": [
    "# 项目一"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3fa7e46c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用模块\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1159fa3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 链接\n",
    "hurun_2022_report_tabel_list = pd.read_html('https://www.hurun.net/zh-CN/Info/Detail?num=L9SQPH9FKJB1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "0da71687",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查列表长度\n",
    "len(hurun_2022_report_tabel_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "963348ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>排名</td>\n",
       "      <td>排名变化</td>\n",
       "      <td>企业名称</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>价值变化（亿元人民币）</td>\n",
       "      <td>国家</td>\n",
       "      <td>城市</td>\n",
       "      <td>行业</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>抖音</td>\n",
       "      <td>13400</td>\n",
       "      <td>-10050</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>社交媒体</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>SpaceX</td>\n",
       "      <td>8400</td>\n",
       "      <td>1680</td>\n",
       "      <td>美国</td>\n",
       "      <td>洛杉矶</td>\n",
       "      <td>航天</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>-1</td>\n",
       "      <td>蚂蚁集团</td>\n",
       "      <td>8000</td>\n",
       "      <td>-2010</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>Stripe</td>\n",
       "      <td>4100</td>\n",
       "      <td>-2210</td>\n",
       "      <td>美国</td>\n",
       "      <td>旧金山</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>Impossible 食品</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>美国</td>\n",
       "      <td>雷德伍德城</td>\n",
       "      <td>食品饮料</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>微医</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>健康科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "      <td>蜂巢能源</td>\n",
       "      <td>460</td>\n",
       "      <td>190</td>\n",
       "      <td>中国</td>\n",
       "      <td>常州</td>\n",
       "      <td>新能源</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>99</td>\n",
       "      <td>-6</td>\n",
       "      <td>Better.com</td>\n",
       "      <td>460</td>\n",
       "      <td>60</td>\n",
       "      <td>美国</td>\n",
       "      <td>纽约</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>99</td>\n",
       "      <td>-20</td>\n",
       "      <td>Automation Anywhere</td>\n",
       "      <td>460</td>\n",
       "      <td>-10</td>\n",
       "      <td>美国</td>\n",
       "      <td>圣何塞</td>\n",
       "      <td>人工智能</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>102 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      0     1                    2          3            4   5      6     7\n",
       "0    排名  排名变化                 企业名称  价值（亿元人民币）  价值变化（亿元人民币）  国家     城市    行业\n",
       "1     1     0                   抖音      13400       -10050  中国     北京  社交媒体\n",
       "2     2     1               SpaceX       8400         1680  美国    洛杉矶    航天\n",
       "3     3    -1                 蚂蚁集团       8000        -2010  中国     杭州  金融科技\n",
       "4     4     0               Stripe       4100        -2210  美国    旧金山  金融科技\n",
       "..   ..   ...                  ...        ...          ...  ..    ...   ...\n",
       "97   95   -16        Impossible 食品        470            0  美国  雷德伍德城  食品饮料\n",
       "98   95   -16                   微医        470            0  中国     杭州  健康科技\n",
       "99   99    58                 蜂巢能源        460          190  中国     常州   新能源\n",
       "100  99    -6           Better.com        460           60  美国     纽约  金融科技\n",
       "101  99   -20  Automation Anywhere        460          -10  美国    圣何塞  人工智能\n",
       "\n",
       "[102 rows x 8 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = hurun_2022_report_tabel_list[-3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "93db2e2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['排名', '排名变化', '企业名称', '价值（亿元人民币）', '价值变化（亿元人民币）', '国家', '城市', '行业']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[0:1].values.tolist()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6887e49b",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.columns = df[0:1].values.tolist()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "aa2f4f90",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>排名</th>\n",
       "      <th>排名变化</th>\n",
       "      <th>企业名称</th>\n",
       "      <th>价值（亿元人民币）</th>\n",
       "      <th>价值变化（亿元人民币）</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>行业</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>抖音</td>\n",
       "      <td>13400</td>\n",
       "      <td>-10050</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>社交媒体</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>SpaceX</td>\n",
       "      <td>8400</td>\n",
       "      <td>1680</td>\n",
       "      <td>美国</td>\n",
       "      <td>洛杉矶</td>\n",
       "      <td>航天</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>-1</td>\n",
       "      <td>蚂蚁集团</td>\n",
       "      <td>8000</td>\n",
       "      <td>-2010</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>Stripe</td>\n",
       "      <td>4100</td>\n",
       "      <td>-2210</td>\n",
       "      <td>美国</td>\n",
       "      <td>旧金山</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "      <td>Shein</td>\n",
       "      <td>4000</td>\n",
       "      <td>2680</td>\n",
       "      <td>中国</td>\n",
       "      <td>广州</td>\n",
       "      <td>电子商务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>Impossible 食品</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>美国</td>\n",
       "      <td>雷德伍德城</td>\n",
       "      <td>食品饮料</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>微医</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>健康科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "      <td>蜂巢能源</td>\n",
       "      <td>460</td>\n",
       "      <td>190</td>\n",
       "      <td>中国</td>\n",
       "      <td>常州</td>\n",
       "      <td>新能源</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>99</td>\n",
       "      <td>-6</td>\n",
       "      <td>Better.com</td>\n",
       "      <td>460</td>\n",
       "      <td>60</td>\n",
       "      <td>美国</td>\n",
       "      <td>纽约</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>99</td>\n",
       "      <td>-20</td>\n",
       "      <td>Automation Anywhere</td>\n",
       "      <td>460</td>\n",
       "      <td>-10</td>\n",
       "      <td>美国</td>\n",
       "      <td>圣何塞</td>\n",
       "      <td>人工智能</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>101 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     排名 排名变化                 企业名称 价值（亿元人民币） 价值变化（亿元人民币）  国家     城市    行业\n",
       "1     1    0                   抖音     13400      -10050  中国     北京  社交媒体\n",
       "2     2    1               SpaceX      8400        1680  美国    洛杉矶    航天\n",
       "3     3   -1                 蚂蚁集团      8000       -2010  中国     杭州  金融科技\n",
       "4     4    0               Stripe      4100       -2210  美国    旧金山  金融科技\n",
       "5     5   11                Shein      4000        2680  中国     广州  电子商务\n",
       "..   ..  ...                  ...       ...         ...  ..    ...   ...\n",
       "97   95  -16        Impossible 食品       470           0  美国  雷德伍德城  食品饮料\n",
       "98   95  -16                   微医       470           0  中国     杭州  健康科技\n",
       "99   99   58                 蜂巢能源       460         190  中国     常州   新能源\n",
       "100  99   -6           Better.com       460          60  美国     纽约  金融科技\n",
       "101  99  -20  Automation Anywhere       460         -10  美国    圣何塞  人工智能\n",
       "\n",
       "[101 rows x 8 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop(0)\n",
    "# 思考：用excel是否能做？要用多长时间？各个部分的情况？\n",
    "# 只需要一个分组运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "141322ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['价值（亿元人民币）'] = df['价值（亿元人民币）'].astype('int32')\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba2feb78",
   "metadata": {},
   "source": [
    "# 分组运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "bb5330c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"4\" halign=\"left\">价值（亿元人民币）</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "      <th>count</th>\n",
       "      <th>sum</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>行业</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>人工智能</th>\n",
       "      <td>870</td>\n",
       "      <td>460</td>\n",
       "      <td>6</td>\n",
       "      <td>870670570500490460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>企业服务</th>\n",
       "      <td>515</td>\n",
       "      <td>1170</td>\n",
       "      <td>2</td>\n",
       "      <td>1170515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>保险</th>\n",
       "      <td>740</td>\n",
       "      <td>740</td>\n",
       "      <td>1</td>\n",
       "      <td>740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>健康科技</th>\n",
       "      <td>840</td>\n",
       "      <td>1040</td>\n",
       "      <td>4</td>\n",
       "      <td>1040840470470</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>共享经济</th>\n",
       "      <td>965</td>\n",
       "      <td>1000</td>\n",
       "      <td>4</td>\n",
       "      <td>1000965700480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>分析</th>\n",
       "      <td>575</td>\n",
       "      <td>575</td>\n",
       "      <td>1</td>\n",
       "      <td>575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>区块链</th>\n",
       "      <td>760</td>\n",
       "      <td>1300</td>\n",
       "      <td>9</td>\n",
       "      <td>30001300760710700575535535500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>大数据</th>\n",
       "      <td>535</td>\n",
       "      <td>2500</td>\n",
       "      <td>2</td>\n",
       "      <td>2500535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>快递</th>\n",
       "      <td>800</td>\n",
       "      <td>1000</td>\n",
       "      <td>4</td>\n",
       "      <td>13201000800720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>教育科技</th>\n",
       "      <td>1500</td>\n",
       "      <td>1500</td>\n",
       "      <td>1</td>\n",
       "      <td>1500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数字科技</th>\n",
       "      <td>2000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新能源</th>\n",
       "      <td>800</td>\n",
       "      <td>460</td>\n",
       "      <td>4</td>\n",
       "      <td>800670640460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新能源汽车</th>\n",
       "      <td>600</td>\n",
       "      <td>1300</td>\n",
       "      <td>2</td>\n",
       "      <td>1300600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新零售</th>\n",
       "      <td>670</td>\n",
       "      <td>670</td>\n",
       "      <td>1</td>\n",
       "      <td>670</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>机器人</th>\n",
       "      <td>575</td>\n",
       "      <td>1200</td>\n",
       "      <td>2</td>\n",
       "      <td>1200575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>消费品</th>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>1</td>\n",
       "      <td>550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>游戏</th>\n",
       "      <td>600</td>\n",
       "      <td>535</td>\n",
       "      <td>2</td>\n",
       "      <td>600535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>物流</th>\n",
       "      <td>870</td>\n",
       "      <td>1200</td>\n",
       "      <td>5</td>\n",
       "      <td>18001200870535500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>生物科技</th>\n",
       "      <td>800</td>\n",
       "      <td>540</td>\n",
       "      <td>2</td>\n",
       "      <td>800540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>电子商务</th>\n",
       "      <td>840</td>\n",
       "      <td>1300</td>\n",
       "      <td>8</td>\n",
       "      <td>40001300840670670580560490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>社交媒体</th>\n",
       "      <td>13400</td>\n",
       "      <td>1000</td>\n",
       "      <td>2</td>\n",
       "      <td>134001000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>网络安全</th>\n",
       "      <td>600</td>\n",
       "      <td>535</td>\n",
       "      <td>3</td>\n",
       "      <td>600555535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>航天</th>\n",
       "      <td>8400</td>\n",
       "      <td>8400</td>\n",
       "      <td>1</td>\n",
       "      <td>8400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>行业</th>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>1</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>软件服务</th>\n",
       "      <td>750</td>\n",
       "      <td>1300</td>\n",
       "      <td>14</td>\n",
       "      <td>17501300750670600570570555520500480480480470</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>金融科技</th>\n",
       "      <td>900</td>\n",
       "      <td>1250</td>\n",
       "      <td>17</td>\n",
       "      <td>8000410022001900165015001250900820800800700670...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>食品饮料</th>\n",
       "      <td>470</td>\n",
       "      <td>1000</td>\n",
       "      <td>2</td>\n",
       "      <td>1000470</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       价值（亿元人民币）                   \\\n",
       "             max        min count   \n",
       "行业                                  \n",
       "人工智能         870        460     6   \n",
       "企业服务         515       1170     2   \n",
       "保险           740        740     1   \n",
       "健康科技         840       1040     4   \n",
       "共享经济         965       1000     4   \n",
       "分析           575        575     1   \n",
       "区块链          760       1300     9   \n",
       "大数据          535       2500     2   \n",
       "快递           800       1000     4   \n",
       "教育科技        1500       1500     1   \n",
       "数字科技        2000       2000     1   \n",
       "新能源          800        460     4   \n",
       "新能源汽车        600       1300     2   \n",
       "新零售          670        670     1   \n",
       "机器人          575       1200     2   \n",
       "消费品          550        550     1   \n",
       "游戏           600        535     2   \n",
       "物流           870       1200     5   \n",
       "生物科技         800        540     2   \n",
       "电子商务         840       1300     8   \n",
       "社交媒体       13400       1000     2   \n",
       "网络安全         600        535     3   \n",
       "航天          8400       8400     1   \n",
       "行业     价值（亿元人民币）  价值（亿元人民币）     1   \n",
       "软件服务         750       1300    14   \n",
       "金融科技         900       1250    17   \n",
       "食品饮料         470       1000     2   \n",
       "\n",
       "                                                          \n",
       "                                                     sum  \n",
       "行业                                                        \n",
       "人工智能                                  870670570500490460  \n",
       "企业服务                                             1170515  \n",
       "保险                                                   740  \n",
       "健康科技                                       1040840470470  \n",
       "共享经济                                       1000965700480  \n",
       "分析                                                   575  \n",
       "区块链                        30001300760710700575535535500  \n",
       "大数据                                              2500535  \n",
       "快递                                        13201000800720  \n",
       "教育科技                                                1500  \n",
       "数字科技                                                2000  \n",
       "新能源                                         800670640460  \n",
       "新能源汽车                                            1300600  \n",
       "新零售                                                  670  \n",
       "机器人                                              1200575  \n",
       "消费品                                                  550  \n",
       "游戏                                                600535  \n",
       "物流                                     18001200870535500  \n",
       "生物科技                                              800540  \n",
       "电子商务                          40001300840670670580560490  \n",
       "社交媒体                                           134001000  \n",
       "网络安全                                           600555535  \n",
       "航天                                                  8400  \n",
       "行业                                             价值（亿元人民币）  \n",
       "软件服务        17501300750670600570570555520500480480480470  \n",
       "金融科技   8000410022001900165015001250900820800800700670...  \n",
       "食品饮料                                             1000470  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(by=['行业']).agg({'价值（亿元人民币）':[max,min,'count',sum]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2542e557",
   "metadata": {},
   "outputs": [],
   "source": [
    "with ps,ExcelWriter('胡润独角兽排行榜整理.xlsx') as writer：\n",
    "    df_国家.to_excel(writer, sheet_name='国家汇总')\n",
    "    df_国家.to_excel(writer, sheet_name='国家汇总')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a73833b1",
   "metadata": {},
   "source": [
    "# requests——html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "133e72d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: requests-html in d:\\program files\\anaconda3\\lib\\site-packages (0.10.0)\n",
      "Requirement already satisfied: pyppeteer>=0.0.14 in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (1.0.2)\n",
      "Requirement already satisfied: pyquery in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (2.0.0)\n",
      "Requirement already satisfied: fake-useragent in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (1.1.1)\n",
      "Requirement already satisfied: parse in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (1.19.0)\n",
      "Requirement already satisfied: requests in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (2.25.1)\n",
      "Requirement already satisfied: bs4 in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (0.0.1)\n",
      "Requirement already satisfied: w3lib in d:\\program files\\anaconda3\\lib\\site-packages (from requests-html) (2.1.1)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.42.1 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (4.59.0)\n",
      "Requirement already satisfied: appdirs<2.0.0,>=1.4.3 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (1.4.4)\n",
      "Requirement already satisfied: pyee<9.0.0,>=8.1.0 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (8.2.2)\n",
      "Requirement already satisfied: certifi>=2021 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (2022.12.7)\n",
      "Requirement already satisfied: importlib-metadata>=1.4 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (3.10.0)\n",
      "Requirement already satisfied: urllib3<2.0.0,>=1.25.8 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (1.26.4)\n",
      "Requirement already satisfied: websockets<11.0,>=10.0 in d:\\program files\\anaconda3\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (10.4)\n",
      "Requirement already satisfied: zipp>=0.5 in d:\\program files\\anaconda3\\lib\\site-packages (from importlib-metadata>=1.4->pyppeteer>=0.0.14->requests-html) (3.4.1)\n",
      "Requirement already satisfied: beautifulsoup4 in d:\\program files\\anaconda3\\lib\\site-packages (from bs4->requests-html) (4.9.3)\n",
      "Requirement already satisfied: soupsieve>1.2 in d:\\program files\\anaconda3\\lib\\site-packages (from beautifulsoup4->bs4->requests-html) (2.2.1)\n",
      "Requirement already satisfied: importlib-resources>=5.0 in d:\\program files\\anaconda3\\lib\\site-packages (from fake-useragent->requests-html) (5.12.0)\n",
      "Requirement already satisfied: lxml>=2.1 in d:\\program files\\anaconda3\\lib\\site-packages (from pyquery->requests-html) (4.6.3)\n",
      "Requirement already satisfied: cssselect>=1.2.0 in d:\\program files\\anaconda3\\lib\\site-packages (from pyquery->requests-html) (1.2.0)\n",
      "Requirement already satisfied: chardet<5,>=3.0.2 in d:\\program files\\anaconda3\\lib\\site-packages (from requests->requests-html) (4.0.0)\n",
      "Requirement already satisfied: idna<3,>=2.5 in d:\\program files\\anaconda3\\lib\\site-packages (from requests->requests-html) (2.10)\n"
     ]
    }
   ],
   "source": [
    "!pip install requests-html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c0a543d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests_html import HTMLSession\n",
    "session = HTMLSession()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95a252a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = session.get('https://www.nfu.edu.cn/xxyw/index.html')\n",
    "r.html.links\n",
    "r.html.ablinks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8dc05cf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# requests-html抓取页面上所有链接"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e364cf2",
   "metadata": {},
   "source": [
    "# 练习：请求学校网站上所有链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a77177ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests_html import HTMLSession\n",
    "session = HTMLSession()\n",
    "r = session.get('https://www.nfu.edu.cn/xxyw/index.html')\n",
    "\n",
    "# 获取页面上所有链接\n",
    "all_links = r.html.links\n",
    "print(all_links)\n",
    "\n",
    "\n",
    "# 从页面上获取所有链接，以绝对路径的方式。\n",
    "all_absolute_link = r.html.absolute_links\n",
    "print(r.html.absolute_links)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a0cec8c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
